/*
 * Team.java
 *
 * Created on 20 marzec 2007, 19:43
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package data;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import util.DatePeriod;

/**
 *
 * @author xavex
 */
public class Team implements Serializable, IDbObject {
    
    private Long id;
    private String name;
    private Set<Employee> members;
    private Set<VacQuota> quotas;
    
    /** Creates a new instance of Team */
    public Team() {
        members = new HashSet<Employee>();
        quotas = new HashSet<VacQuota>();                
    }
    

    public Long getId() {
        return this.id;
    }

    private void setId(final Long id) {
        this.id = id;
    }

    public Set<Employee> getMembers() {
        return this.members;
    }

    public void setMembers(final Set<Employee> members) {
        this.members = members;
    }

    public String getName() {
        return this.name;
    }

    public void setName(final String name) {
        this.name = name;
    }

    public Set<VacQuota> getQuotas() {
        return this.quotas;
    }
    
    public Set<VacQuota> getQuotas( DatePeriod period ) {
        Set<VacQuota> q = new HashSet<VacQuota>();
        
        for( VacQuota quota : quotas ) {
            DatePeriod p = new DatePeriod( quota.getFromDate(), quota.getToDate() );
            
            if( p.overlaps( period ) )
                q.add( quota );
        }
        
        return q;
    }

    public void setQuotas(final Set<VacQuota> quotas) {
        this.quotas = quotas;
    }
    
    public String toString()
    {
        return getName();
    }
    
  public boolean equals(Object aThat)
  {
      if ( this == aThat ) return true;
      if ( !(aThat instanceof Team) ) return false;

      if( id == null )
          return super.equals( aThat );
      else
          return this.id.equals( ((Team)aThat).id );
  }
  
  public int hashCode()
  {
        if( id != null )
            return id.hashCode();
        else
            return super.hashCode();
  }
  
}
